import { ColumnProps, PaginationConfig } from "antd/lib/table";
import * as React from "react";
import { IColumn, ORDER_TYPE } from "../../interfaces";
import { defaultState } from "../../store/reducer";
import Action_add from "../action/add";
import Action_edit from "../action/edit";
import { formatTimeStamp10 } from "../../../../../common/tools/time_utils";

// 获取分页信息
export function getPaginationInfo(total: number): PaginationConfig {
  return {
    total,
    defaultCurrent: defaultState.table_filter.pageNum,
    defaultPageSize: defaultState.table_filter.pageSize,
    showSizeChanger: true, //是否可以改变pageSize
    showQuickJumper: true, //跳转
    showTotal: (total: number, _: any) => `共${total}条`,
    pageSizeOptions: ["10", "20", "50"], //每页条数选项,
    position: "bottom"
  };
}

export function columnsFun() {
  const columns: ColumnProps<IColumn>[] = [
    {
      title: (
        <React.Fragment>
          <Action_add />
        </React.Fragment>
      ),
      key: "action",
      render: (_: any, record: IColumn) => (
        <span>
          <Action_edit record={record} />
        </span>
      )
    },
    {
      title: "ID",
      dataIndex: "id",
      key: "id",
      sorter: true
    },
    {
      title: "编号",
      dataIndex: "code",
      key: "code"
    },
    {
      title: "正在使用的IP",
      dataIndex: "useIp",
      key: "useIp"
    },
    {
      title: "类型",
      key: "type",
      dataIndex: "type",
      render: (_text, record) => {
        for (let i = 0; i < ORDER_TYPE.length; i++) {
          if (record.type == ORDER_TYPE[i].id) {
            return ORDER_TYPE[i].value;
          }
        }
        return "未知";
      }
    },
    {
      title: "下一次提取时间",
      key: "nextTime",
      dataIndex: "nextTime",
      render: (_text, record) => {
        return formatTimeStamp10(record.nextTime);
      }
    },
    {
      title: "生成时间",
      key: "createdTime",
      dataIndex: "createdTime"
    },
    {
      title: "到期时间",
      key: "expiryTime",
      dataIndex: "expiryTime",
      sorter: true,
      render: (_text, record) => {
        return formatTimeStamp10(record.expiryTime);
      }
    },
    {
      title: "支付金额",
      key: "payMoney",
      dataIndex: "payMoney"
    },
    {
      title: "所属用户",
      key: "ownerUsername",
      dataIndex: "ownerUsername"
    },
    {
      title: "修改时间",
      key: "updatedTime",
      dataIndex: "updatedTime"
    },
    {
      title: "备注",
      key: "note",
      dataIndex: "note"
    }
  ];
  return columns;
}
